<?php 

class mysql_class {
	var $setting_file = "../config/config.php";
	var $db;
	var $query;
	var $result;
	var $row;
	var $dataset;
	var $data_seek;
	var $free_result;
	var $num_rows;

	function mysql_class($persist = 1) {
	
		include("$this->setting_file");
			$this->host 	= $hostname_cn;
			$this->database = $database_cn;
			$this->user		= $username_cn;
			$this->password = $password_cn;	
				
		if($persist <= 1 || $persist > 2) { 
			$this->connect();
		} else {
			$this->connectp();
		}
	}
	

	function connect(){
		$this->db = mysql_connect($this->host,$this->user,$this->password) or die('Error connecting to the server '.mysql_error());
		mysql_select_db($this->database,$this->db) or die('Error selecting database');
	}
	
	function connectp() {
		$this->db = mysql_pconnect($this->host,$this->user,$this->password) or die('Error connecting to the server '.mysql_error());
		mysql_select_db($this->database,$this->db) or die('Error selecting database');
	}	
	
	function execute($query){
		$this->query 	= $query;
		$this->result 	=  mysql_query($query, $this->db);	
	}
	
	function get_array(){
		if($this->row = mysql_fetch_array($this->result)){
			return $this->row;
		}else{
			return false;
		}
	}
	
	function get_row(){
		if($this->row = mysql_fetch_array($this->result)){
			return $this->row;
		}else{
			return false;
		}
	}
	
	function get_object(){
		if($this->row = mysql_fetch_object($this->result)){
			return $this->row;
		}else{
			return false;
		}
	}
	
	function get_dataset(){
		$dataset = array();
		$i = 0;
		while($r = mysql_fetch_row($this->result)){
			$field = 0;
			for($field = 0; $field < mysql_num_fields($this->result);$field++){
				$dataset[$i][$field] = $r[$field];
			}
			$i++;
		}
		return $dataset;
	}
	
	function get_num_rows(){
		$this->num_rows = mysql_num_rows($this->result);
		return $this->num_rows;
	}
	
	function data_seek($cnt){
		$this->data_seek = mysql_data_seek($this->result, $cnt);
		return $this->data_seek;
	}	
	
	function free_result(){
		$this->free_result = mysql_free_result($this->result);
		return $this->free_result;
	}		
	
	function close(){
		mysql_close($this->db);
	}
}//end class mysql
?>